import { Application } from 'egg';
import {
  list,
  create,
  update,
  destroyRule,
} from '../validate/module';
/**
 * 用户相关的路由
 */
export default (app: Application) => {
  const { auth } = app.middleware;
  const {
    jwt
  } = app;

  return {
    'auth.module.list': {
      method: 'GET',
      path: '/api/auth/module/list',
      options: {
        tags: ['auth/module'],
        description: '模块列表',
        handler: app.controller.auth.module.list,
        middlewares: [jwt, auth('auth.module.list')],
        validate: list,
      },
    },
    'auth.module.create': {
      method: 'POST',
      path: '/api/auth/module',
      options: {
        tags: ['auth/module'],
        description: '添加模块',
        handler: app.controller.auth.module.create,
        middlewares: [jwt, auth('auth.module.create')],
        validate: create,
      },
    },
    'auth.module.update': {
      method: 'PUT',
      path: '/api/auth/module/:id',
      options: {
        tags: ['auth/module'],
        description: '修改模块详情',
        handler: app.controller.auth.module.update,
        middlewares: [jwt, auth('auth.module.update')],
        validate: update,
      },
    },
    'auth.module.destroy': {
      method: 'DELETE',
      path: '/api/auth/module/:id',
      options: {
        tags: ['auth/module'],
        description: '删除模块',
        handler: app.controller.auth.module.destroy,
        middlewares: [jwt, auth('auth.module.destroy')],
        validate: destroyRule,
      },
    },
  }
};
